package cq.com.cn.servlet;

import cq.com.cn.model.GoodsCardModel;
import cq.com.cn.model.UserModel;
import cq.com.cn.service.GoodsCardService;
import cq.com.cn.utils.AjaxUtils;
import cq.com.cn.utils.Constants;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/goodscard/queryGoods.do")
public class QueryGoodsCardServlet  extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //判断用户是否登录
        Object obj = req.getSession().getAttribute(Constants.SEESIONKEY);

        UserModel user = (UserModel) obj;
        GoodsCardService goodsCardService = new GoodsCardService();
        List<GoodsCardModel> goodsCardLists = goodsCardService.queryGoodsCardByUserId(user.getId());
        req.setAttribute("goodsCardLists",goodsCardLists);
        req.getRequestDispatcher("/view/goodscard.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}